#include "pixelfont.h"
#include "graphics.h"

void PixelFont::setVariableWidthAscii(SDL_Surface * a_surface, 
		const int & a_startingLetter, const int & a_numLetters)
{
	m_surface = a_surface;
	m_start = a_startingLetter;
	m_end = m_start + a_numLetters;
	m_letters.allocateToSize(a_numLetters);
	SPoint cursor(0, a_surface->h-1);
	SPoint letterStart;
	int markerValue = VSDL_getSurfacePixel(a_surface, cursor);
	for(int i = 0; i < a_numLetters; ++i)
	{
		letterStart.set(cursor.getX(), 0);
		do{
			cursor.addX(1);
		}while(VSDL_getSurfacePixel(a_surface, cursor) != markerValue
			&& cursor.getX() < a_surface->w);
		m_letters.get(i).set(letterStart, cursor);

		SRect r = m_letters.get(i);
	}
}

void PixelFont::drawGlyph(SDL_Surface * a_dest, 
	const int & tile, const SPoint & cursor)
{
	SRect src = getImageSourceOf(tile);
	SRect dest;
	dest.setPosition(cursor);
	SDL_BlitSurface(m_surface, &src, a_dest, &dest); 
}
